

[fn,fp] = uigetfile('.avi','select eye movies','MultiSelect','on');
cd(fp)
selectionfigure = figure;
for n = 1:length(fn)
    v = VideoReader(fn{n});
    im = read(v,2);
    im = im(:,:,1);
    imagesc(im);
    title(fn{n})
    disp('Draw ROI')
    s = 0;
    while s ~= 1
        roi = drawpolygon;
        s = input('Keep selected [1/0]? ');
        if s == -1
            break;
        end
    end
    if s == -1
        continue;
    end
    bw = createMask(roi);
    savename = strrep(fn{n},'.avi','_EyeMask.mat');
    movname = fn{n};
    save(savename,'bw','movname');
end
clear v
